package com.wit.service.impl;

import hibernate.HibernateSessionFactory;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;

import com.wit.dao.CompanyDao;
import com.wit.po.Company;
import com.wit.po.Subcompany;
import com.wit.service.CompanyService;

public class CompanyServiceImpl implements CompanyService{
	
	private CompanyDao companyDao;

	public CompanyDao getCompanyDao() {
		return companyDao;
	}

	public void setCompanyDao(CompanyDao companyDao) {
		this.companyDao = companyDao;
	}


	public boolean addCompany(Company company) {
		// TODO Auto-generated method stub
		return companyDao.addCompany(company);
	}

	
	public boolean deleteCompany(Company company) {
		// TODO Auto-generated method stub
		return companyDao.deleteCompany(company);
	}

	
	public List<Company> findCompanyByCondition(DetachedCriteria dc,Integer startRecord, Integer pageSize) {
		// TODO Auto-generated method stub
		return companyDao.findCompanyByCondition(dc,startRecord,pageSize);
	}

	
	public Company findCompanyByIdenfier(String companyNum) {
		// TODO Auto-generated method stub
		return companyDao.findCompanyByIdenfier(companyNum);
	}

	
	public boolean modifyCompany(Company company) {
		// TODO Auto-generated method stub
		return companyDao.modifyCompany(company);
	}

	
	public List<Company> findAllCompany() {
		// TODO Auto-generated method stub
		DetachedCriteria dc = DetachedCriteria.forClass(Company.class);
		return companyDao.findCompanyByCondition(dc,0,1000);
	}

	
	public Integer findCompanyCount(DetachedCriteria dc) {
		// TODO Auto-generated method stub
		return companyDao.findCompanyCount(dc);
	}
	 public static void main(String[] args)
		{
			Session se=HibernateSessionFactory.getSession();
			Subcompany su=(Subcompany)se.createQuery("from Subcompany where subcommpanyId='SC001'").uniqueResult();
			System.out.println(su.getCompany().getCompanyNum());
				
		}

}
